package com.egao.common.module.statistics.service.impl;

import cn.hutool.core.util.StrUtil;
import com.egao.common.core.web.JsonResult;
import com.egao.common.module.statistics.service.SchoolHitsStatisticsService;
import com.egao.common.module.statistics.utils.CreateTimeHorizonUtils;
import com.egao.common.publicly.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 网站统计接口实现类
 *
 * @author pyx
 * @date 2021/5/12
 */
@Service
public class SchoolHitsStatisticsServiceImpl implements SchoolHitsStatisticsService {
    @Autowired
    private PubliclyArticleService publiclyArticleService;
    @Autowired
    private PubliclyPreachService publiclyPreachService;
    @Autowired
    private PubliclyMutualService publiclyMutualService;
    @Autowired
    private PubliclyOuterPreachService publiclyOuterPreachService;
    @Autowired
    private PubliclyOuterMutualService publiclyOuterMutualService;
    @Autowired
    private PubliclyRecruitService publiclyRecruitService;
    @Autowired
    private PubliclySelectColumnService publiclySelectColumnService;
    @Autowired
    private PubliclyPreachCloudService publiclyPreachCloudService;
    @Autowired
    private PubliclyOfficialService publiclyOfficialService;
    @Autowired
    private PubliclyLectureService publiclyLectureService;

    @Override
    public JsonResult HitsStatistics(String createTimeHorizon) {

        HashMap<String, String> createTimeMap = new HashMap<>();
        Map<String, Integer> map = new HashMap<>();

        if(!StrUtil.isBlank(createTimeHorizon)){
            createTimeMap = CreateTimeHorizonUtils.putTime(createTimeHorizon);
        }

        //新闻,公告的总点击量
        int articledHits = publiclyArticleService.allHists(createTimeMap, Arrays.asList(3, 2));
        map.put("articledHists",articledHits);

        //校内宣讲会总点击量
        int preachHits = publiclyPreachService.allHists(createTimeMap);
        map.put("preachHists",preachHits);

        //校内双选会点击总量
        int mutualHits = publiclyMutualService.allHists(createTimeMap);
        map.put("mutualHists",mutualHits);

        //校外双选会总点击量
        int outerPreachHits = publiclyOuterPreachService.allHists(createTimeMap);
        map.put("outerMutualHists",outerPreachHits);

        //校外双选会总点击量
        int outerMutualHits = publiclyOuterMutualService.allHists(createTimeMap);
        map.put("outerMutualHits",outerMutualHits);

        //在线招聘总点击量(type = 1为在线招聘)
        int recruitOnline = publiclyRecruitService.allHists(createTimeMap,1);
        map.put("recruitOnline",recruitOnline);

        //实习招聘总点击量(type = 2为实习招聘)
        int recruitPracticeHits = publiclyRecruitService.allHists(createTimeMap,2);
        map.put("recruitPracticeHits",recruitPracticeHits);

        //选调专栏总点击量
        int selectColumnHits = publiclySelectColumnService.allHists(createTimeMap);
        map.put("selectColumnHits",selectColumnHits);

        //空中宣讲会总点击量
        int preachCloudHits = publiclyPreachCloudService.allHists(createTimeMap);
        map.put("preachCloudHits",preachCloudHits);

        //公考资讯总点击量
        int officialHits = publiclyOfficialService.allHists(createTimeMap);
        map.put("officialHits",officialHits);

        //就业讲座总点击量
        int lectureHits = publiclyLectureService.allHists(createTimeMap);
        map.put("lectureHits",lectureHits);

        //政策指南总点击量
        int guideHits = publiclyArticleService.allHists(createTimeMap,Arrays.asList(25,31,15));
        map.put("guideHits",guideHits);

        return JsonResult.ok().put("map",map);
    }
}
